package appcore

import (
	"net/http"
	"strings"

	"gitee.com/chenrh/ios-local/AppDdistribute/internal/svc"

	"github.com/zeromicro/go-zero/rest"
)

func dirHandler() http.HandlerFunc {
	return func(w http.ResponseWriter, req *http.Request) {
		handler := http.StripPrefix(`/static/`, http.FileServer(http.Dir(`./static/`)))
		handler.ServeHTTP(w, req)
	}
}

func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
	dirlevel := []string{":1", ":2", ":3", ":4", ":5", ":6", ":7", ":8", ":8"}
	for i := 1; i < len(dirlevel); i++ {
		path := `/static/` + strings.Join(dirlevel[:i], "/")
		server.AddRoute(
			rest.Route{
				Method:  http.MethodGet,
				Path:    path,
				Handler: dirHandler(),
			})
	}
}
